// 两个日期之前的间隔
const dayDif = (day1, day2) => {
  return Math.ceil(Math.abs(day1.getTime() - day2.getTime()) / 86400000);
};
// 查找日期位于一年中的第几天
const dayOfYear = (date) => {
  return Math.floor(
    (date - new Date(date.getFullYear(), 0, 0)) / 1000 / 60 / 60 / 24
  );
};
console.log(dayOfYear(new Date()));
// 字符串首字母大写
// charAt 返回指定下标的字符
const capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1);
console.log(capitalize("woshiren"));
// 翻转字符串
const reverseStr = (str) => str.split("").reverse().join("");
console.log(reverseStr("123"));
// 从数组中移除重复项
// 扩展运算符 ... 中括号  能使new Set()变成数组
const removeDupl = (arr) => [...new Set(arr)];
console.log(removeDupl([1, 1, 1, 1, 3, 3, 4, 4, 4]));

// 浏览器操作
// 复制内容到剪切板
const copyToClipboard = (text) => navigator.clipboard.writeText(text);
// 判断是否是苹果设备
const isAppleDevice = () => /Mac|iPod|iPhone|iPad/.test(navigator.platform);
// 是否滚动到页面底部
const scrolledToBottom = () =>
  document.documentElement.clientHeight + window.scrollY >=
  document.documentElement.scrollHeight;
// 返回顶部
const goToTop = () => window.scroll(0, 0);

// 检测js对象是否为空
const isEmpty = (obj) =>
  Reflect.ownKeys(obj).length === 0 && obj.constructor === Object;
